/**
 * Created by yongwang on 2015/6/15.
 */
var geekService = require('../../services/backoffice/backOffice-geekService');
var messageUtil = require('../../common/utils/messageUtil');
var toolUtil = require('../../common/utils/toolUtil');
var mysqlUtil = require('../../common/utils/mysqlUtil');


exports.getGeekList = function(req, res){
    var input = req.body,
        map = {
            communityId: input.communityId,
            starttime: input.starttime,
            endtime: input.endtime,
            status: input.status,
            nickname: input.nickname,
            phone: input.phone
        },
        page = req.params.page;

    logger.info(input);
    geekService.getGeekList(map,page,function (err, result) {
        if (err) {
            logger.error('Exception happened when geekList...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happened when geekList...!' + err.message));
        } else {
            for(var i = 0;i < result[2].length;i++){
                result[2][i]._doc.questionLength = result[0][i].q;
                result[2][i]._doc.activityLength = result[1][i].a;
                result[2][i]._doc.replyLength = result[0][i].r + result[1][i].r;
                result[2][i]._doc.praiseLength = result[0][i].p + result[1][i].p;
                result[2][i]._doc.levelLength = result[0][i].l + result[1][i].l;
            }

            res.json(messageUtil.composeSucceededMessage(req, null, result[2]));
        }
    });
};
